﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server
{
    public interface IHandler
    {
        void Register(Dictionary<Protocal, Action<SocketClient,ByteBuffer>> handers);
    }
    public class HandlerCenter
    {
        //所有协议对应的处理函数
        Dictionary<Protocal, Action<SocketClient, ByteBuffer>> handlers = new Dictionary<Protocal, Action<SocketClient, ByteBuffer>>();

        AccountHandler accountHandler = new AccountHandler();
        BattleHandler battleHandler = new BattleHandler();

        public HandlerCenter()
        {
            accountHandler.Register(handlers);
            battleHandler.Register(handlers);
        }

        public void ReceiveMessage(SocketClient client, ByteBuffer buffer)
        {
            Protocal type = (Protocal)buffer.ReadByte();
            handlers[type](client, buffer);
        }
    }
}
